<template>
  <div class="app-header">
    <h2 class="app-header__title">{{ appTitle }}</h2>

    <div class="app-header__action">
      <slot />
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import router from '../router'

export default defineComponent({
  name: 'AppHeader',

  props: {
    /** 标题 */
    title: {
      type: String,
      default: ''
    }
  },

  setup(props) {
    return {
      appTitle: computed(() => props.title || router.currentRoute.meta?.title || '')
    }
  }
})
</script>

<style lang="scss" scoped>
.app-header {
  position: relative;
  z-index: 1;
  height: 48px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);

  &__title {
    margin: 0;
    font-size: 16px;
    line-height: 48px;
    text-align: center;
  }

  &__action {
    position: absolute;
    top: 0;
    right: 16px;
    display: flex;
    align-items: center;
    height: 100%;
  }
}
</style>
